package com.xiaolin.io;

import java.io.*;

/**
 * @ClassName TestBufferedInputStream
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/9/26
 * @Version 1.0
 */
public class TestBufferedInputStream {
    public static void main(String[] args) throws IOException {
        boolean b = readAndWrite("D:\\1file\\功能分析.doc", "D:\\1file\\out.doc");
        System.out.println(b);
    }

    /**
     * 字节流缓冲流
     * @param origin
     * @param dest
     * @return
     */
    public static boolean readAndWrite(String origin,String dest){
        BufferedInputStream inputStream = null;
        BufferedOutputStream outputStream =null;
        try {
            inputStream = new BufferedInputStream(new FileInputStream(origin));
            outputStream=new BufferedOutputStream(new FileOutputStream(dest));
            byte[] bytes=new byte[1024*5];
            int len=0;
            while ((len=inputStream.read(bytes)) != -1){
                outputStream.write(bytes,0,len);
            }
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (inputStream!=null){
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (outputStream!=null){
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }
}
